package com.ng.framework.view.desktop;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JComboBox;

public class NGCombo extends JComboBox {

	private static final long serialVersionUID = 5012855765637156365L;

	private List objetos = new ArrayList();

	public NGCombo() {
	}

	public void addNGItems(List items) {
		objetos.addAll(items);
		for (Object object : items) {
			this.addItem(object != null ? object.toString() : null);
		}
	}

	public void setSelectedNGItem(Object object) {
		this.setSelectedItem(object.toString());
	}

	public Object getSelectedNGItem() {
		return objetos.get(this.getSelectedIndex());
	}

	public <T> T getSelectedNGItem(Class<T> clazz) {
		T selectedNGItem = null;
		if (this.getSelectedIndex() != -1) {
			selectedNGItem = (T) objetos.get(this.getSelectedIndex());
		}
		return selectedNGItem;
	}

	public void addNGItem(Object object) {
		this.addItem(object != null ? object.toString() : null);
		this.objetos.add(object);

	}

	public void removeAllNGItems() {
		super.removeAllItems();
		this.objetos.clear();

	}
}
